package com.yst.web.utils;

import java.util.LinkedList;
import java.util.List;

public class ListUtils {
    /**
     * Loop copy
     * @param source source list
     * @param startIndex copy start index
     * @param copySize copy size
     * @return
     */
    public static List copy(List source,int startIndex,int copySize){
        List result=new LinkedList<>();
        for(int i=startIndex;i<startIndex+copySize;i++){
            result.add(source.get(i%source.size()));
        }
        return result;
    }

    /**
     * Get loop next index
     * @param source source list
     * @param index current index
     * @return next index ,if value more than size return begin index
     */
    public static int getNextLoopIndex(List source,int index){
        int next=index+1;
        if (next>=source.size()){
            next=0;
        }
        return next;
    }
}
